package com.lhb.mapper;

import com.github.pagehelper.Page;
import com.lhb.dto.StudentAddDTO;
import com.lhb.dto.StudentEditDTO;
import com.lhb.dto.StudentPageQueryDTO;
import com.lhb.entity.Student;
import com.lhb.vo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudentMapper {


    /**
     * 获得学生数据
     * @param studentPageQueryDTO
     * @return
     */
    Page<StudentVO> getStudent(StudentPageQueryDTO studentPageQueryDTO);





    /**
     * 删除用户
     * @param idList
     */
    void deleteStudent(List<Long> idList);

    /**
     * 更新student表
     * @param studentEditDTO
     */
    @Update("update student set profession=#{profession},my_class=#{myClass},phone=#{phone},id_card=#{idCard},sex=#{sex} where id=#{id}")
    void updateStudent(StudentEditDTO studentEditDTO);

    /**
     * 更新family表
     *
     * @param familyDetailVO
     */
    @Update("update family set name=#{name},work_place=#{workPlace},business_name=#{businessName},phone=#{phone} where student_id=#{studentId} and tag_name=#{tagName}")
    void updateFamily(FamilyDetailVO familyDetailVO);

    /**
     * 更新award表
     *
     * @param award
     */
    @Update("update award set award_name=#{awardName},award_level=#{awardLevel},award_date=#{awardDate} where student_id=#{studentId} and id=#{id}")
    void updateAward(AwardDetailVO award);

    /**
     * 添加
     * @param student
     */
    @Insert("insert into student(id,name, profession, my_class, phone, id_card, sex,enroll_date) values (#{id},#{name},#{profession},#{myClass},#{phone},#{idCard},#{sex},#{enrollDate})")
    void saveStudent(Student student);

    /**
     * 添加
     *
     * @param familyDetailVO
     */
    @Insert("insert into family(tag_name, name, work_place, business_name, phone, student_id) values (#{tagName},#{name},#{workPlace},#{businessName},#{phone},#{studentId})")
    void saveFamily(FamilyDetailVO familyDetailVO);

    /**
     * 添加
     *
     * @param awardDetailVO
     */
    @Insert("insert into award(award_name, award_level, award_date, student_id) VALUES (#{awardName},#{awardLevel},#{awardDate},#{studentId}) ")
    void saveAward(AwardDetailVO awardDetailVO);

    @Select("select * from family where student_id=#{id}")
    List<FamilyDetailVO> getFamily(Long studentVO);

    @Select("select * from award where student_id=#{id}")
    List<AwardDetailVO> getAward(Long studentVO);

    @Select("select * from student where id=#{id}")
    Student getStudentById(Long id);

    void deleteFamily(List<Long> idList);

    void deleteAward(List<Long> idList);
}
